home *** CD-ROM | disk | FTP | other *** search
/ AOL File Library: 2,801 to 2,900 / aol-file-protocol-4400-2801-to-2900.zip / AOLDLs / C++ Files Library / HyperCuber Source / HyperCuber 2.0 Source.sit / HyperCuber 2.0 Source / CHyperCuberPane.cp < prev    next >
Text File  |  1994-05-03  |  9KB  |  272 lines

  1. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2. // CHyperCuberPane.c
  3. //
  4. // This file contains the implementation of the pane for the graphic window.
  5. //___________________________________________________________________________
  6.  
  7. #include "CControlsDirector.h"
  8. #include "CGraphic.h"
  9. #include "CHyperCuberApp.h"
  10. #include "CHyperCuberDoc.h"
  11. #include "CHyperCuberPane.h"
  12. #include "CHyperCuberPrefs.h"
  13. #include "CHyperScrollBar.h"
  14. #include "CRotateMouseTask.h"
  15. #include "HyperCuber Commands.h"
  16. #include "HyperCuber Messages.h"
  17.  
  18. #include <LongQD.h>
  19.  
  20.  
  21. //============================ Constants ============================\\
  22.  
  23. #define    Pi    3.14159265358979323846
  24.  
  25.  
  26. //============================ Globals ============================\\
  27.  
  28. Boolean                drawing_disabled = FALSE;    //  TRUE if drawing is disabled
  29.  
  30. extern CHyperCuberPrefs    *gPrefs;
  31.  
  32. extern short        menubar_height;                //  The height of the menubar (if any)
  33.  
  34.  
  35. //============================ Prototypes ============================\\
  36.  
  37. extern void create_offscreen_pixmap(CGrafPort *color_port, Rect *bounds);
  38. extern void adjust_offscreen_pixmap(CGrafPort *color_port, Rect *bounds);
  39. extern void dispose_offscreen_pixmap(CGrafPort *color_port);
  40.  
  41.  
  42.  
  43. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  44. //| CHyperCuberPane::IHyperCuberPane
  45. //|
  46. //| Purpose: Initialize a HyperCuberPane
  47. //|
  48. //| Parameters: same as Pane
  49. //|______________________________________________________________
  50.  
  51. void CHyperCuberPane::IHyperCuberPane(CView *anEnclosure, CBureaucrat *aSupervisor,
  52.                             short aWidth, short aHeight,
  53.                             short aHEncl, short aVEncl,
  54.                             SizingOption aHSizing, SizingOption aVSizing)
  55. {
  56.  
  57. //    char    axes_3D_string[] = "0,0,1.3 0,0,-1.3 0,1.3,0 0,-1.3,0 1.3,0,0 -1.3,0,0\n1#1 2#1\n3#1 4#1\n5#1 6#1";
  58. //    char    axes_4D_string[] = "1.3,0,0,0 -1.3,0,0,0 0,1.3,0,0 0,-1.3,0,0 0,0,1.3,0 0,0,-1.3,0 0,0,0,1.3 0,0,0,-1.3\n1#1 2#1\n3#1 4#1\n5#1 6#1\n7#1 8#1";
  59.  
  60.     CPane::IPane(anEnclosure, aSupervisor, aWidth, aHeight,            //  Initialize as a Pane
  61.                             aHEncl, aVEncl, aHSizing, aVSizing);
  62.  
  63.     Rect port_bounds = {0, 0, aHeight, aWidth};                        //  Create the offscreen port
  64.     create_offscreen_pixmap(&OffscreenPort, &port_bounds);
  65.     
  66.     StereoMode = mono;                                    //  Don't draw in stereo
  67.     fAddOver = FALSE;                                    //  Don't use addOver mode
  68.     fAntialias = FALSE;                                    //  Don't antialias
  69.     fUseNativeColors = TRUE;                            //  Use the object's native colors
  70.     fDrawOffscreen = TRUE;                                //  Draw offscreen
  71.  
  72. }    //==== CHyperCuberPane::IHyperCuberPane() ====\\
  73.  
  74.  
  75.  
  76. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  77. //| CHyperCuberPane::Dispose
  78. //|
  79. //| Purpose: Dispose of a CHyperCuberPane
  80. //|
  81. //| Parameters: none
  82. //|_________________________________________________________
  83.  
  84. void CHyperCuberPane::Dispose()
  85. {
  86.  
  87.     dispose_offscreen_pixmap(&OffscreenPort);    //  Dispose of the associated offscreen port
  88.  
  89.     inherited::Dispose();                        //  Dispose of the pane
  90.  
  91. }    //==== CHyperCuberPane::Dispose() ====\\
  92.  
  93.  
  94.  
  95. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  96. //| CHyperCuberPane::Draw
  97. //|
  98. //| Purpose: Refresh the graphics pane
  99. //|
  100. //| Parameters: area: the part of the pane to draw
  101. //|______________________________________________________________
  102.  
  103. void CHyperCuberPane::Draw(Rect *area)
  104. {
  105.  
  106.     RGBColor rgb_black = {0, 0, 0};
  107.  
  108.     if (fAntialias)
  109.         graphic->ClearDrawingArea(&rgb_black);    //  Background must be black for antialiasing
  110.  
  111.     else
  112.         graphic->ClearDrawingArea(
  113.             &gPrefs->prefs.background_color);    //  No antialiasing; use selected background color
  114.  
  115.     graphic->Draw();                            //  Draw the object
  116.  
  117. }    //==== CHyperCuberPane::Draw() ====\\
  118.  
  119.  
  120.  
  121. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  122. //| CHyperCuberPane::AdjustToEnclosure
  123. //|
  124. //| Purpose: This is called when the window is resized.  It keeps  the
  125. //|          graphics panes square.
  126. //|
  127. //| Parameters: passed on to superclass
  128. //|______________________________________________________________________
  129.  
  130. void    CHyperCuberPane::AdjustToEnclosure(Rect *deltaEncl)
  131. {
  132.  
  133.     drawing_disabled = FALSE;                    //  Assume that this adjustment will make the
  134.                                                 //    panes small enough to fit in memory
  135.  
  136.     CPane::AdjustToEnclosure(deltaEncl);        //  Adjust this and all subpanes
  137.  
  138.     FitToEnclosure(TRUE, TRUE);                    //  Fill the enclosure
  139.     Refresh();                                    //  Force this window to be redrawn (eventually)
  140.     
  141.     CHyperCuberDoc *doc =
  142.             (CHyperCuberDoc *) itsSupervisor;    //  Get the document
  143.  
  144.     short aspect_ratio =                        //  Use 2:1 aspect ratio for two-image stereo, 1:1 for normal
  145.         (StereoMode == two_image_stereo) ? 2 : 1;
  146.  
  147.     short    width, height;
  148.     GetLengths(&width, &height);                //  Find the new size of the pane
  149.     
  150.     Rect change_rect = {0, 0, 0, 0};            //  Make pane fit the aspect ratio
  151.     short size;
  152.     if (width > aspect_ratio * height)
  153.         {
  154.         size = aspect_ratio * height;
  155.         change_rect.right = size - width;
  156.         }
  157.     else
  158.         {
  159.         size = width;
  160.         change_rect.bottom = size / aspect_ratio - height;
  161.         }
  162.         
  163.     ChangeSize(&change_rect, FALSE);
  164.     CenterWithinEnclosure(TRUE, TRUE);    
  165.  
  166.     Rect bounds;
  167.     LongToQDRect(&frame, &bounds);                //  Find size of pane
  168.     
  169.     adjust_offscreen_pixmap(&OffscreenPort,        //  Make offscreen bitmap large enough
  170.                                 &bounds);
  171.     graphic->FitToPane();                            //  Remap the graphic to the new pane size
  172.  
  173. }    //==== CHyperCuberPane::AdjustToEnclosure() ====\\
  174.  
  175.  
  176.  
  177. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  178. // Procedure CHyperCuberPane::UpdateGraphicsPanes
  179. //
  180. // Purpose: Recompute and redraw the graphics pane
  181. //
  182. // Parameters: main_pane: the main pane
  183. //_________________________________________________________
  184.  
  185. void CHyperCuberPane::UpdateGraphicsPanes(void)
  186. {
  187.  
  188.     LongRect graphics_rect;
  189.     Prepare();                                //  Erase the pane
  190.     GetFrame(&graphics_rect);
  191.     LEraseRect(&graphics_rect);                    
  192.  
  193.     Rect no_movement = {0, 0, 0, 0};
  194.     AdjustToEnclosure(&no_movement);        //  Recalc positions of graphics panes
  195.  
  196.     Refresh();                                //  Redraw the object
  197.  
  198. }    //==== CHyperCuberPane::UpdateGraphicsPanes() ====\\
  199.  
  200.  
  201. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  202. //| CHyperCuberPane::DoClick
  203. //|
  204. //| Purpose: This is called when the user clicks in the pane
  205. //|
  206. //| Parameters: hit_point: the point where the click occurred
  207. //|             modifiers: modifiers from mouseDown event
  208. //|             when:      when the click occurred
  209. //|______________________________________________________________
  210.  
  211. void CHyperCuberPane::DoClick(Point hit_point, short modifiers, long when)
  212. {
  213.  
  214.     Point global_point = hit_point;
  215.     LocalToGlobal(&global_point);                        //  Find click's global coordinates
  216.     if (global_point.v < menubar_height)
  217.         {
  218.         DoCommand(cmdToggleMenuBar);                    //  If the click was in the (hidden) menubar,
  219.         return;                                            //    show the menubar.
  220.         }
  221.  
  222.     mouse_task_struct    h_mouse_tasks[MAX_MOUSE_CONTROLS];
  223.     mouse_task_struct    v_mouse_tasks[MAX_MOUSE_CONTROLS];
  224.     short num_h_tasks = 0;
  225.     short num_v_tasks = 0;
  226.  
  227.     CHyperCuberDoc *doc = (CHyperCuberDoc *) itsSupervisor;    //  Get the document
  228.  
  229.     long graphic_dimension = doc->graphic->dimension;        //  Find dimension of graphic
  230.  
  231.     long i;
  232.     for (i = 0; i < gPrefs->prefs.num_mouse_controls; i++)    //  Loop through all mouse controls
  233.         {
  234.         mouse_control_struct mouse_control =
  235.                     gPrefs->prefs.mouse_controls[i];        //  Get point to mouse controls
  236.         if ((mouse_control.modifiers == modifiers) &&
  237.             (mouse_control.dimension <= graphic_dimension))    //  Use this task if the modifier keys
  238.                                                             //   are right and the dimension is
  239.                                                             //   no more than the graphic dimension
  240.             {
  241.             
  242.             mouse_task_struct mouse_task;
  243.             
  244.             mouse_task.controls_director =
  245.                 (CControlsDirector *)
  246.                     doc->controls_directors->
  247.                         NthItem(mouse_control.dimension);    //  Find controls for this dimension
  248.             
  249.             mouse_task.angle = mouse_control.angle;            //  Get angle to change
  250.             mouse_task.multiplier =
  251.                                 mouse_control.multiplier;    //  Get multiplier
  252.             
  253.             if (mouse_control.horiz)                        
  254.                 h_mouse_tasks[num_h_tasks++] = mouse_task;    //  Add task to horizontal tasks array
  255.             
  256.             else
  257.                 v_mouse_tasks[num_v_tasks++] = mouse_task;    //  Add task to vertical tasks array
  258.             }
  259.         }
  260.  
  261.     CRotateMouseTask *mouse_task = new (CRotateMouseTask);
  262.     mouse_task->IRotateMouseTask(this, h_mouse_tasks,
  263.                 v_mouse_tasks, num_h_tasks, num_v_tasks);    //  Initialize mouse task
  264.  
  265.     LongRect pin_rect = {-10000, -10000, 10000, 10000};
  266.     LongPt long_hit_point;
  267.     QDToLongPt(hit_point, &long_hit_point);    
  268.     TrackMouse(mouse_task, &long_hit_point, &pin_rect);
  269.  
  270. }    //==== CHyperCuberPane::DoClick() ====\\
  271.  
  272.